<?php
	$category_id = $params[0];
	if($_SERVER["REQUEST_METHOD"]=='POST') {
		$title			= strip_tags($_POST['title']);
		$status			= $_POST['status']=='publish' ? '1': '0';

		$upload_fieldname	= 'thumb';
		$upload_extension	= file_ext($_FILES[$upload_fieldname]['name']);
		$upload_fullpath	= '../contents/category_gallery/'.md5('thumb'.time()).$upload_extension;
		if (move_uploaded_file($_FILES[$upload_fieldname]['tmp_name'], $upload_fullpath)) {
			$upload_sql = ", `thumb` = '". basename($upload_fullpath) ."'";
		}
		
		$sql = "UPDATE `tbl_category_gallery` SET `title` = '$title' $upload_sql , `status` = '$status' WHERE  `category_id` = '$category_id' LIMIT 1;";
		mysql_query($sql);
		redirect('../');
		exit;
	}

	$sql = "SELECT * FROM `tbl_category_gallery` WHERE `category_id` = '$category_id' LIMIT 1";
	$query = mysql_query($sql);
	while($result = mysql_fetch_assoc($query)) {
		$title			= $result['title'];
		$thumbHTML		= $result['thumb'] ? "<img src=\"/thumb/195/115/zc/contents/category_gallery/{$result['thumb']}\" /><br />": "";
	}
	mysql_free_result($query);
?>